package main

import (
	"sync"
	"time"
)

// _compute value int: 输入值 wg *sync.WaitGroup: 等待组，用于同步 results chan<- int: 只写通道，用于发送结果
func _compute(value int, wg *sync.WaitGroup, results chan<- int) {
	defer wg.Done()
	time.Sleep(time.Duration(value) * 10000 * time.Microsecond)
	results <- value * value
}

//func main() {
//	var wg sync.WaitGroup
//	results := make(chan int, 5)
//
//	for i := 1; i < 5; i++ {
//		wg.Add(1)
//		go _compute(i, &wg, results)
//	}
//
//	go func() {
//		wg.Wait()
//		close(results)
//	}()
//
//	for result := range results {
//		fmt.Println("result:", result)
//	}
//	fmt.Println("All compute finish")
//}
